from common.connect_db import MyDB

my_db = MyDB()


class DataBaseAgent:

    @staticmethod
    def filter_life_agent_users_any(**kwargs):
        """
        根据任意自定义条件查找代理商信息
        :param kwargs:
        :return:
        """
        condition = ""
        for k, v in kwargs.items():
            condition += " and %s = '%s'" % (k, v)

        sql = "select * from life_agent_users where %s and status in (1,3)" % condition[4:]
        result = my_db.execute_select('agent', sql)
        if len(result) == 1:
            return result[0]
        elif len(result) == 0:
            return result
        else:
            raise ValueError('SQL执行出错，请检查')

    @staticmethod
    def filter_life_agent_pay_costs_by_agent_id(agent_id):
        """
        根据代理商ID获得详细信息
        :param agent_id:
        :return:
        """
        sql = "select * from life_agent_pay_costs where agent_id = '%s'" % agent_id
        result = my_db.execute_select('agent', sql)
        if len(result) == 1:
            return result[0]
        elif len(result) == 0:
            return result
        else:
            raise ValueError('SQL执行出错，请检查')


if __name__ == '__main__':
    pass
